package com.example.sqltest.repository;

import com.example.sqltest.pojo.AgentUserLog;
import com.example.sqltest.vo.AgentUserLogVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: dangwen
 * @createDate: 2020/12/2
 */
@Repository
public interface AgentUserLogRepository extends JpaRepository<AgentUserLog,Integer>, JpaSpecificationExecutor<AgentUserLog> {

//    @Query(value = "SELECT new com.example.sqltest.vo.AgentUserLogVo(al,a) from AgentUserLog al , AgentUser a where al.beOperatedAccount = a.username and a.nickName = ?1")
//    List<AgentUserLogVo> findAgentUserLogVoList(String nickName);
    @Query(value = "SELECT new com.example.sqltest.vo.AgentUserLogVo(al,a) from AgentUserLog al , AgentUser a where al.beOperatedAccount = a.username and  a.nickName = ?1")
    List<AgentUserLogVo> findAgentUserLogVoList(String nickName);



//    //第一种方式，使用nativeQuery = true
//    @Query(value = "SELECT fixed,park.parkName AS parkName FROM FixedValidityTermEntity fixed " +
//            "LEFT JOIN ParkingLotsEntity park ON fixed.parkingLotId = park.id " +
//            "WHERE IF(:parkingLotId IS NOT NULL ,fixed.parkingLotId = :parkingLotId ,1 = 1 ) ",nativeQuery = true)
//    List<Object> findAllByParkingLotId(String parkingLotId);
////第二种方式
//    @Query(value = "SELECT fixed,park.parkName AS parkName FROM FixedValidityTermEntity fixed " + "LEFT JOIN ParkingLotsEntity park ON fixed.parkingLotId = park.id " +
//            "WHERE 1=1 AND (:parkingLotId IS NULL OR :parkingLotId = '' OR fixed.parkingLotId = :parkingLotId ) ")
//    List<Object> findAllByParkingLotId(String parkingLotId);


}
